#ifndef STRUCTS_H
#define STRUCTS_H

/*
 * errors
 */
typedef enum
	/*{{{*/
{
	 SCDBXML_OK = 0,
		 SCDBXML_PREPARE,
		 SCDBXML_FINALIZE,
		 SCDBXML_OPEN,
		 SCDBXML_CLOSE,
		 SCDBXML_EXEC,
		 SCDBXML_BEGIN,
		 SCDBXML_COMMIT,
		 SCDBXML_MALLOC,
		 SCDBXML_BIND,
		 SCDBXML_STEP,
		 SCDBXML_RESET,
		 SCDBXML_XML,
		 SCDBXML_FILE
}
/*}}}*/
ctxtError;


/*
 * struct for nodes
 * needed for depth first parse of document
 */
typedef struct _node
	/*{{{*/
{
	 int x; /* x index of node */
	 int y; /* y index of node */
	 int depth; /* depth of node */
	 xmlElementType type; /* element, attribute or text */
	 int nod_id; /* id of node once inserted */
	 int doc_id; /* id of document containing node */
	 
	 xmlChar *uri; /* namespace URI */
	 int uri_len; /* length of ns URI */
	 
	 xmlChar *prefix; /* namespace prefix */
	 int prefix_len; /* length of prefix */

	 xmlChar *name; /* name of node */
	 int name_len; /* length of name */
	 
	 xmlChar *value; /* value of node */
	 int value_len; /* length of value */
} 
/*}}}*/
*node;

/*
 * user context for reading from xml documents into database
 * which holds stack of nodes, database handle,
 * precompiled statements
 * and magic number for nodes and depth
 */
typedef struct _userwriterctxt 
	/*{{{*/
{
	 struct _node *nodes; /* nodes buffer */
	 int node_count; /* number of nodes in buffer */
	 int max_nodes; /* maximum length of buffer */
	 
	 xmlEntityPtr entities; /* linked list for entities */

	 sqlite3 *db; /* database handle */

	 /* 
		* precompiled insert statements
		*/
	 sqlite3_stmt *insertDoc;
	 sqlite3_stmt *insertNod;
	 sqlite3_stmt *insertElm;
	 sqlite3_stmt *insertAtt;
	 sqlite3_stmt *insertTxt;
	 sqlite3_stmt *insertEns;
	 sqlite3_stmt *insertAns;
	 sqlite3_stmt *insertPI;
	 sqlite3_stmt *insertCom;
	 
	 int magic; /* number for x and y of nodes */
	 int depth; /* depth of parse */
	 
	 char *xmlfile; /* name of xml file */
	 int doc_id; /* id of document when inserted */
	 
	 ctxtError error; /* error code */
	 int line; /* line where error was trapped */
	 char *file; /* file where error was trrapped */
}
/*}}}*/
*userWriterCtxt;

/*
 * user context for reading from database into xml document
 */
typedef struct _userreaderctxt
	/*{{{*/
{
	 struct _node *nodes; /* nodes buffer */

	 int node_count; /* number of nodes in buffer */
	 int max_nodes; /* maximum length of buffer */
	 int depth; /* depth of parse */

	 sqlite3 *db; /* database handle */
	 sqlite3_stmt *getDocument; /* query for document */
	 xmlDocPtr doc; /* XML document to build up */
	 ctxtError error; /* error code */
	 int line; /* line where error was trapped */
	 char *file; /* file where error was trrapped */
}
/*}}}*/
*userReaderCtxt;

#endif
